<template>
    <view class="SRV-topbar">
        <view class="left">
            <uni-icons type="back" size="22" color="#000" @click="backFan()" v-if="isLeft" />
            <uni-icons type="home" size="22" color="#000" @click="jump('index','')" v-if="isLeft" />
            <!-- <uni-icons type="search" size="22" color="#000" @click="jump('search','')" v-if="!isLeft"/> -->
            <uni-icons type="scan" size="22" color="#000" @tap="getScancode" v-if="!isLeft"/>
        </view>
        <view class="title">
            <text>{{title}}</text>
        </view>
        <view class="right">
            
            <!-- <uni-icons type="email-filled" size="22" color="#000" @click="jump('message','')" /> -->
            <!-- <view class="messageNum" v-if="messageNum > 0"></view> -->
        </view>
    </view>


</template>

<script>
    import common from '@/static/jump.js';
    export default {
        name: "SRV-topbar",
        data() {
            return {

            }
        },
        props: {
            title: { // 页面标题文字
                type: String,
                default: ""
            },
            isLeft: { //是否显示主页按钮
                type: [Boolean, String],
                default: false
            },
            messageNum: { //消息数量
                type: [Number, String],
                default: 0
            },
        },
        methods: {
            backFan(){
            	var Pagecount = getCurrentPages().length;  
            	if(Pagecount>1){
            		this.jump('return_one','')
            	}else{
            		this.jump('index','')
            	}
            	
            },
            jump(jump_type, jump_link) {
                common.jump(jump_type, jump_link);
            },
            getScancode: function() {
                var self = this;
                // 允许从相机和相册扫码
                wx.scanCode({
                    success: (res) => {
                        var result = res.result;
						console.info(result);
                        uni.redirectTo({
                            url: '/pages/common/scancode?q=' + encodeURIComponent(result)
                        });
                        return;
                    }
                })
            },
        },
        onLoad() {

        }
    }
</script>

<style scoped lang="scss">
    .SRV-topbar {
        width: 100%;
        height: 160upx;
        background-color: #ffd900;

        .left {
            // width: 180upx;
            height: 60upx;
            line-height: 60rpx;
            overflow: hidden;
            position: absolute;
            top: 100upx;
            display: flex;

            uni-icons {
                margin-left: 20upx;
            }
        }

        .title {
            width: calc(100% - 330upx);
            height: 60upx;
            overflow: hidden;
            position: absolute;
            top: 100upx;
            left: 180upx;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            align-content: center;

            text {
                height: 32upx;
                text-align: center;
                font-size: 30upx;
                line-height: 32upx;
                font-weight: bold;
                overflow: hidden;
                color: #000;
                text-overflow: -o-ellipsis-lastline;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 1;
                -webkit-box-orient: vertical;
            }
        }

        .right {
            width: 150upx;
            height: 60upx;
            line-height: 60rpx;
            overflow: hidden;
            position: absolute;
            top: 100upx;
            display: flex;
            right: 0upx;

            uni-icons {
                margin-left: 20upx;
            }
        }
        .messageNum{
            width: 15upx;
            height: 15upx;
            background: red;
            border-radius: 50%;
            position: absolute;
            top: 10upx;
            right: 20upx;
        }
    }
</style>
